<template>
  <div class="list">
        <el-table
        :data="book"
        style="width: 100%">
        <el-table-column
        prop="name"
        label="用户名"
        width="180">
        </el-table-column>
        <el-table-column
        prop="address"
        label="房间号"
        width="180">
        </el-table-column>
        <el-table-column
        prop="money"
        label="金额/h"
        width="180">
        </el-table-column>
        <el-table-column
        prop="bookTime"
        label="预定时间">
        </el-table-column>
        <el-table-column
        prop="endTime"
        label="取消预定时间">
        </el-table-column>
        <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button :disabled="scope.row.state ===0 ?false  : true" type="text"  @click="finishBook(scope.row)">用户入住</el-button>
      </template>
    </el-table-column>
       
        </el-table>
        <div class="pager">
          <el-pagination
            background
            layout="prev, pager, next,total"
            :total="total"
            :page-size="pageData.pageSize"
            @current-change="handlePage">
          </el-pagination>
        </div>
        

    </div>
</template>

<script>
import { getBookAdmin } from '@/api/book'
import { addBill } from '@/api/bill'
export default {
  name:'',
  components: {  },
  data() {
    return {
        book:[],
        pageData:{
          page: 1,
          pageSize: 11,
        },
        total:0,
    }
  },
  methods:{
    getList(){
      getBookAdmin({params:this.pageData}).then( res =>{
        // console.log('很要命-------',res);
        let {data,code,msg} = res.data
        if(code == 1){
          this.book = data.records
          this.total = Number(data.total)
        }else{
          this.$message.error(msg)
        }
      }).catch(err =>{
        this.$message.error('连接后端失败',err)
      })
    },
    handlePage(val){
        this.pageData.page = val
        this.getList()
    },
    finishBook(row){
      let params = {
        customerId : row.customerId,
        roomId : row.roomId,
        bookId :row.id,
      }
      addBill(params).then(res =>{
        // console.log('很要命--addbill-----',res,);
        let {data,code,msg} = res.data
        if(code === 1){
          this.getList()
          this.$message.success(data)
        }else{
          this.$message.error(msg)
        }
      }).catch(err =>{
        this.$message.error('后端出现错误',err)
      })
      

    }
  },
  mounted(){
    this.getList()
  }

}
</script>

<style lang="less" scoped>

.pager{
    position: absolute;
    bottom: 30px;
    // right: 20px;
    left: 50%;
  }
</style>